
const dbConfig = require("./index")
const dayjs = require('dayjs')
const { Parameters } = require('../utils/utils')
//获取所有的上传的图片列表
const getFileList = (req, res) => {
  let sql = `select * from tool.file`
  let sqlArr = []
  dbConfig.sqlConnect(sql, sqlArr, (data, err) => {
    if (err) return res.sends('参数错误')
    //返回数据
    res.sends(data)
  }, res)
}

//添加一条上传记录
const addFileItem = (req, res) => {
  const { keys, values, num } = new Parameters(req.body).add({ userId: req.userId, createTime: dayjs().format('YYYY-MM-DD') })
  const sql = `insert into tool.file(${keys}) values(${num})`
  dbConfig.sqlConnect(sql, [...values], (data, err) => {
    if (err) return res.sends(err)
    res.sends({
      url: req.body.url,
      fileName: req.body.fileName
    });
  }, res)
}
module.exports = { getFileList, addFileItem }
